#include <stdio.h>
#include <stdint.h>
#include <string.h>

#define SIZE 30

struct sensor
{
    uint8_t day;
    uint8_t month;
    uint16_t year;
    int8_t t;
};

void changeIJ (struct sensor* info, int i, int j)
{
    struct sensor temp;
    temp   =info[i];
    info[i]=info[j];
    info[j]=temp;
};

void SortByT(struct sensor* info, int n)
{
    for (int i=0; i<n; ++i)
    {
        for (int j=i; j<n; ++j)
        {
            if(info[i].t>=info[j].t)
            {
                changeIJ(info,i,j);
            }
        }
    }
}

unsigned int DateToInt(struct sensor* info)
{
    return info->year << 16|info->month <<8|info->day;
};

void SortByDate(struct sensor* info, int n)
{
    for (int i=0; i<n; ++i)
    {
        for (int j=i; j<n; ++j)
        {
            if(DateToInt(info+i)>=DateToInt(info+j))
            {
                changeIJ(info,i,j);
            }
        }
    }
}

void AddRecord(struct sensor* info, int number, uint16_t year, uint8_t month, uint8_t day, int8_t t)
{
    info[number].year=year;
    info[number].month=month;
    info[number].day=day;
    info[number].t=t;
}

int AddInfo(struct sensor *info)
{
    int counter=0;
    AddRecord(info,counter++,2021,9,16,9);
    AddRecord(info,counter++,2022,9,2,-9);
    AddRecord(info,counter++,2021,1,7,8);
    AddRecord(info,counter++,2021,9,5,1);
    return counter;
}

void print(struct sensor *info, int number)
{
    printf("====================================\n");
    for(int i=0; i<number;i++)
    {
        printf("%04d-%02d-%02d t=%3d\n",
        info[i].year,
        info[i].month,
        info[i].day,
        info[i].t
        );
    }
}

int DelRecord(struct sensor *info,int del, int n)
{
    for (int i=del; i<n; i++)
    {
        info[i]=info[i+1];
    }
    return n-1;
}

int main(int argc, char **argv)
{
    struct sensor info[SIZE];
    int number=AddInfo(info);

    print(info,number);
    printf("%d \n", DateToInt(&info[2]));
    // number=DelRecord(info,1,number);
    // print(info,number);


}